import { defineStore } from 'pinia'

// 创建一个新的 store 实例
export const useMainStore = defineStore('main', {
    state: () => {
        return {
            token: "",
            dictTree: [
                {
                    "id": "1810479819725475841",
                    "pid": "0",
                    "code": "layerPage",
                    "name": "聚合页分类",
                    "value": null,
                    "sort": 13,
                    "status": 1,
                    "remark": null,
                    "type": 1,
                    "createTime": null,
                    "updateTime": "2024-07-09 09:03:21",
                    "children": [
                        {
                            "id": "1810479887710949378",
                            "pid": "1810479819725475841",
                            "code": "sj",
                            "name": "数据分析",
                            "value": "sj",
                            "sort": 1,
                            "status": 2,
                            "remark": null,
                            "type": null,
                            "createTime": null,
                            "updateTime": "2025-06-25 09:16:07",
                            "children": []
                        },
                        {
                            "id": "1810479943008653314",
                            "pid": "1810479819725475841",
                            "code": "yw",
                            "name": "业务中心",
                            "value": "yw",
                            "sort": 2,
                            "status": 1,
                            "remark": null,
                            "type": null,
                            "createTime": null,
                            "updateTime": "2024-07-09 09:03:50",
                            "children": []
                        },
                        {
                            "id": "1810479998226665473",
                            "pid": "1810479819725475841",
                            "code": "jc",
                            "name": "基础资源",
                            "value": "jc",
                            "sort": 3,
                            "status": 1,
                            "remark": null,
                            "type": null,
                            "createTime": null,
                            "updateTime": "2024-07-09 09:04:03",
                            "children": []
                        }
                    ]
                },
            ],
            dictTreeAll: [
                {
                    "id": "1810479819725475841",
                    "pid": "0",
                    "code": "layerPage",
                    "name": "聚合页分类",
                    "value": null,
                    "sort": 13,
                    "status": 1,
                    "remark": null,
                    "type": 1,
                    "createTime": null,
                    "updateTime": "2024-07-09 09:03:21",
                    "children": [
                        {
                            "id": "1810479887710949378",
                            "pid": "1810479819725475841",
                            "code": "sj",
                            "name": "数据分析",
                            "value": "sj",
                            "sort": 1,
                            "status": 2,
                            "remark": null,
                            "type": null,
                            "createTime": null,
                            "updateTime": "2025-06-25 09:16:07",
                            "children": []
                        },
                        {
                            "id": "1810479943008653314",
                            "pid": "1810479819725475841",
                            "code": "yw",
                            "name": "业务中心",
                            "value": "yw",
                            "sort": 2,
                            "status": 1,
                            "remark": null,
                            "type": null,
                            "createTime": null,
                            "updateTime": "2024-07-09 09:03:50",
                            "children": []
                        },
                        {
                            "id": "1810479998226665473",
                            "pid": "1810479819725475841",
                            "code": "jc",
                            "name": "基础资源",
                            "value": "jc",
                            "sort": 3,
                            "status": 1,
                            "remark": null,
                            "type": null,
                            "createTime": null,
                            "updateTime": "2024-07-09 09:04:03",
                            "children": []
                        }
                    ]
                },
            ],
            isFullscreen: false,
            audioChecked: false,
            tabArr: [],
        }
    },
    /*    
    变更
    demoStore.$patch((state) => {
    state.arr.push(3)
    state.isAdmin= false
    })
    demoStore.$reset()   // 重置 
    // */
    // //声明操作数据的方法 action
    actions: {
        SET_TOKEN(data) {
            this.token = data
        },
        SET_DICT(data) {
            // this.dictTree = data
        },
        SET_IsFullscreen(data) {
            this.isFullscreen = data
        },
        SET_audioChecked(data) {
            this.audioChecked = data
        },
        SET_tabArr(data) {
            this.tabArr = data
        }
    },
    getters: {
        // 计算属性
        // 返回2倍数的count
        doubleCount(state) {
            return state.count * 2
        },
    },
    // 持久化存储
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'main',
                storage: localStorage,
                paths: ['token', 'dictTreeAll', 'isFullscreen', 'audioChecked', 'tabArr']
            },
        ],
    }
})
